package com.macro.mall.controller;

import com.macro.mall.common.api.CommonResult;
import com.macro.mall.model.PmsProductTags;
import com.macro.mall.service.PmsProductTagsService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author：尚志豪
 * @Package：com.macro.mall.controller
 * @Project：mall-swarm-B
 * @name：PmsProductTagsController
 * @Date：2024/10/31 10:17
 */
@Controller
@Tag(name = "PmsProductTags",description = "商品类型标签管理")
@RequestMapping("/tags")
public class PmsProductTagsController {

    @Autowired
    private PmsProductTagsService pmsProductTagsService;

    /**
     * 获取商品类型标签
     */
    @Operation(summary = "获取商品类型标签")
    @RequestMapping(value = "/listAll/{categoryId}", method = RequestMethod.GET)
    @ResponseBody
    public CommonResult<List<PmsProductTags>> getList(@PathVariable Integer categoryId) {
        return CommonResult.success(pmsProductTagsService.listAll(categoryId));
    }

    /**
     * 添加标签
     */
    @Operation(summary = "添加标签")
    @RequestMapping(value = "/create", method = RequestMethod.POST)
    @ResponseBody
    public CommonResult create(@RequestBody PmsProductTags productTags){
        pmsProductTagsService.createTags(productTags);
        return CommonResult.success(null,"添加成功");
    }

    /**
     * 删除标签
     */
    @Operation(summary = "删除标签")
    @RequestMapping(value = "/delete/{id}", method = RequestMethod.DELETE)
    @ResponseBody
    public CommonResult delete(@PathVariable Integer id){
        pmsProductTagsService.delete(id);
        return CommonResult.success(null,"删除成功");
    }

    /**
     * 查看标签详细
     */
    @Operation(summary = "查看标签详细")
    @RequestMapping(value = "/find/{id}", method = RequestMethod.DELETE)
    @ResponseBody
    public CommonResult<PmsProductTags> find(@PathVariable Integer id) {
        PmsProductTags productTags = pmsProductTagsService.find(id);
        return CommonResult.success(productTags,"成功");
    }

    /**
     * 修改标签内容
     */
    @Operation(summary = "修改标签内容")
    @RequestMapping(value = "/upd}", method = RequestMethod.DELETE)
    @ResponseBody
    public CommonResult upd(@RequestBody PmsProductTags productTags){
        pmsProductTagsService.upd(productTags);
        return CommonResult.success(null,"修改成功");
    }
}
